#define DEBUG
#include <cstdio>
#include <cstring>
#define INF 0xffffffff
#define MAXN 100000
#define MAXK 6

using namespace std;

unsigned int fact[MAXN+1];

void initFact(unsigned int n) {
  fact[0]=1;
  for (unsigned int i=1; i<=n; i++) {
    fact[i] = fact[i-1]*i;
  }
}

int min(int a, int b) {
  return a<b ? a : b;
}

int max(int a, int b) {
  return a>b ? a : b;
}

void mergeMin(unsigned int a[2], unsigned int b[2], unsigned int c[2]) {
  if (a[0]<b[0]) {
    c[0]=a[0], c[1]=a[1];
  } else {
    c[0]=b[0], c[1]=b[1];
  }
}

void mergeF(unsigned int a[MAXK+1], unsigned int b[MAXK+1], unsigned int c[MAXK+1]) {
  c[0]=1;
  for (int i=1; i<=MAXK; i++) {
    c[i]=0;
    for (int j=0; j<=i; j++) {
      c[i] += a[j]*b[i-j];
    }
  }
}

class SegmentTree {
public:
  unsigned int minv[4*MAXN+1][2], f[4*MAXN+1][MAXK+1];

  void build(int o, int l, int r, int *a) {
    if (l==r) {
      f[o][1]=minv[o][0]=a[l];
      f[o][0]=1, minv[o][1]=l;
    } else {
      int mid=(l+r)/2;
      build(o*2, l, mid, a);
      build(o*2+1, mid+1, r, a);
      mergeMin(minv[o*2], minv[o*2+1], minv[o]);
      mergeF(f[o*2], f[o*2+1], f[o]);
    }
  }

  void get(int o, int l, int r, int tl, int tr, unsigned int tmin[2], unsigned int tf[MAXK+1]) {
    if (tl>tr) {
      return;
    }
    if (l==tl && r==tr) {
      mergeMin(tmin, minv[o], tmin);
      static unsigned int temf[MAXK+1];
      memcpy(temf, tf, sizeof(temf));
      mergeF(temf, f[o], tf);
    } else {
      int mid=(l+r)/2;
      if (tl<=mid && tr>=l) {
	get(o*2, l, mid, max(tl, l), min(tr, mid), tmin, tf);
      }
      if (tl<=r && tr>mid) {
	get(o*2+1, mid+1, r, max(tl, mid+1), min(tr, r), tmin, tf);
      }
    }
  }
};

void sort(int *d, int *v, int l, int r) {
  int i=l, j=r, mid=d[(l+r)/2], temp;
  for (; i<=j; ) {
    for (; d[j]>mid; j--);
    for (; d[i]<mid; i++);
    if (i<=j) {
      temp=d[i], d[i]=d[j], d[j]=temp;
      temp=v[i], v[i]=v[j], v[j]=temp;
      i++, j--;
    }
  }
  if (i<r) {
    sort(d, v, i, r);
  }
  if (j>l) {
    sort(d, v, l, j);
  }
}

int findAbove(int *a, int n, int t) {
  int ret=0;
  for (int l=1, r=n, mid; l<=r; ) {
    mid=(l+r)/2;
    if (a[mid]>=t) {
      ret = mid;
      r = mid-1;
    } else {
      l = mid+1;
    }
  }
  return ret;
}

int findBelow(int *a, int n, int t) {
  int ret=0;
  for (int l=1, r=n, mid; l<=r; ) {
    mid=(l+r)/2;
    if (a[mid]<=t) {
      ret = mid;
      l = mid+1;
    } else {
      r = mid-1;
    }
  }
  return ret;
}

int main() {
#ifdef DEBUG
  freopen("4237.in", "r", stdin);
  freopen("4237.out", "w", stdout);
#endif

  static int d[MAXN+1], v[MAXN+1];
  int n, q;
  scanf("%d %d", &n, &q);
  initFact(n);
  for (int i=1; i<=n; i++) {
    scanf("%d", d+i);
  }
  for (int i=1; i<=n; i++) {
    scanf("%d", v+i);
  }
  sort(d, v, 1, n);

  static SegmentTree sgt;
  sgt.build(1, 1, n, v);

  for (int i=1; i<=q; i++) {
    int l, r, k;
    scanf("%d %d %d", &l, &r, &k);
    int lpos=findAbove(d, n, l), rpos=findBelow(d, n, r);
    if (rpos-lpos>=k) {
      static unsigned int minp[2], sumv[2][MAXK+1], temp[2];
      minp[0]=INF;
      sgt.get(1, 1, n, lpos, rpos, minp, sumv[0]);
      for (int i=1; i<=MAXK+1; i++) {
	sumv[0][i]=sumv[1][i]=0;
      }
      sumv[0][0]=sumv[1][0]=1;
      sgt.get(1, 1, n, lpos, minp[1]-1, temp, sumv[0]);
      sgt.get(1, 1, n, minp[1]+1, rpos, temp, sumv[1]);
      unsigned int ans=0;
      for (int i=0; i<=k; i++) {
	ans += sumv[0][i]*sumv[1][k-i];
      }
      printf("%u\n", ans*fact[k]);
    } else {
      printf("0\n");
    }
  }

  fcloseall();
  return 0;
}
